//
//  WeChatShareHandler.m
//  LQShare
//
//  Created by 陈宪栋 on 16/7/19.
//  Copyright © 2016年 hzdracom. All rights reserved.
//

#import "WeChatShareHandler.h"
#import "WXApiRequestHandler.h"
#import "WXApi.h"

@implementation WeChatShareHandler
+ (BOOL)sendLinkURL:(NSString *)urlString TagName:(NSString *)tagName Title:(NSString *)title Description:(NSString *)description ThumbImage:(UIImage *)thumbImage InScene:(enum WXScene)scene {
    if (![WXApi isWXAppInstalled]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"未安装微信" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return NO;
    }
    if (![WXApi isWXAppSupportApi]) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"当前微信版本太低，需要更新" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return NO;
    }
    return [WXApiRequestHandler sendLinkURL:urlString TagName:tagName Title:title Description:description ThumbImage:[self imageWithImage:thumbImage] InScene:scene];
}


+ (UIImage *)imageWithImage:(UIImage*)image {
    CGSize newSize = CGSizeMake(200, 200);
    UIGraphicsBeginImageContext(newSize);
    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    NSData *imageData = UIImageJPEGRepresentation(newImage, 0.8);
    
    return [UIImage imageWithData:imageData];
}
@end
